import request from '@/utils/request'
// import qs from 'qs'

// 删除IPS
export function delIps (params) {
  var data = fromData(params)
  return request({
    url: '/ips/del_ips',
    method: 'post',
    data
  })
}

// 增加IPS
export function addIps (params) {
  var data = fromData(params)
  return request({
    url: '/ips/addIps',
    method: 'post',
    data
  })
}

// 编辑IPS
export function editIps (params) {
  var data = fromData(params)
  return request({
    url: '/ips/editIps',
    method: 'post',
    data
  })
}

// 获取IPS策略列表
export function getIpsArray (params) {
  var data = fromData(params)
  return request({
    url: '/ips/getIpsArray',
    method: 'post',
    data
  })
}

// 获取规则集列表
export function getRuleArray (params) {
  var data = fromData(params)
  return request({
    url: '/ips/getRuleArray',
    method: 'post',
    data
  })
}

// 获取规则集类型列表
export function getRuleType (params) {
  var data = fromData(params)
  return request({
    url: '/ips/getRuleType',
    method: 'post',
    data
  })
}

// 获取详细信息
export function getRuleInfo (params) {
  var data = fromData(params)
  return request({
    url: '/ips/getInfo',
    method: 'post',
    data
  })
}

// 获取规则集名称
export function getIpsName (params) {
  var data = fromData(params)
  return request({
    url: '/ips/getIpsName',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
